﻿using System.Windows;
using System.Windows.Controls;

namespace Alimentador.CustomControls
{
    /// <summary>
    /// Interaction logic for AddMealCtrl.xaml
    /// </summary>
    public partial class AddMealCtrl : UserControl
    {
        public delegate MealCtrl AddMealEventDelegate(string mealName);
        public delegate void RemoveMealEventDelegate();

        public event AddMealEventDelegate AddMealEvent;
        public event RemoveMealEventDelegate RemoveMealEvent;

        public AddMealCtrl()
        {
            InitializeComponent();

            NewMealNameToAdd_cb.SelectedIndex = 1;
        }

        private void AddMealBtn_Click(object sender, RoutedEventArgs e)
        {
            if (AddMealEvent != null)
            {
                ComboBoxItem selectedItem = (ComboBoxItem)NewMealNameToAdd_cb.SelectedItem;
                AddMealEvent((string)selectedItem.Content);

                if (NewMealNameToAdd_cb.SelectedIndex < NewMealNameToAdd_cb.Items.Count)
                {
                    NewMealNameToAdd_cb.SelectedIndex = NewMealNameToAdd_cb.SelectedIndex + 1;
                }
            }
        }

        private void NewMealNameToAdd_cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            AddMealBtn.IsEnabled = NewMealNameToAdd_cb.SelectedIndex >= 0;
        }

        private void RemoveMealBtn_Click(object sender, RoutedEventArgs e)
        {
            if (RemoveMealEvent != null)
            {
                RemoveMealEvent();
            }
        }
    }
}
